﻿using System;
using Algoritmia.DataStructures.Lists;
using Algoritmia.DataStructures.Queues;
using Algoritmia.Utils;

namespace Algoritmia.Schemes.BranchAndBound
{
    public class BranchAndBoundDecision<TDecision>
    {
        private readonly BranchAndBoundDecision<TDecision> _previousDecision;
        private readonly TDecision _decision;

        public BranchAndBoundDecision(TDecision decision = default(TDecision), BranchAndBoundDecision<TDecision> previous = null)
        {
            _decision = decision;
            _previousDecision = previous;
        }

        public IList<TDecision> RecoverDecisions(Func<ILifo<TDecision>> createLifo = null)
        {
            createLifo = createLifo ?? (() => AlgoritmiaFactory.Lifos<TDecision>.Default);

            var lifo = createLifo();
            var current = this;
            while ( current != null && current._previousDecision != current)
            {
                lifo.Push(current._decision);
                current = current._previousDecision;
            }
            return lifo.ToAlgoritmiaList();
        }

    }
}
